package com.totoro.mongo.collection;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class TestDemo {
    private static ExecutorService dealService = Executors.newFixedThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r) ;
            thread.setDaemon(true);
            return thread ;
        }
    });
    private static void start(){
        System.out.println(dealService.isShutdown());
        System.out.println(dealService.isTerminated());
        dealService.submit(new Runnable() {
            @Override
            public void run() {
                int i=0 ;
                while(true){
                    i++ ;
                    try {
                        Thread.sleep(400);
                        System.out.println(i);
                        if(i==100000)
                            return ;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }

            }
        }) ;
        System.out.println(dealService.isShutdown() );
    }

    private static void stop(){
        if(!dealService.isShutdown())
            dealService.shutdown();
    }

    public static void main(String[] args) {
        start() ;
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        stop();
    }
}
